import wx

class MyPopupMenu(wx.Menu):
    def __init__(self, parent):
        super(MyPopupMenu,self).__init__()
        self.parent = parent
        mmi = wx.MenuItem(self, wx.ID_ANY, "Minimize")
        self.Append(mmi)
        self.Bind(wx.EVT_MENU, self.OnMinimize, mmi)

        cmi = wx.MenuItem(self, wx.ID_ANY, "Close")
        self.Append(cmi)
        self.Bind(wx.EVT_MENU, self.OnClose, cmi)

    def OnMinimize(self, e):
        self.parent.Iconize()
    def OnClose(self, e):
        self.parent.Close()

class Example(wx.Frame):
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
        self.InitUI()
    def InitUI(self):
        self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)

    def OnRightDown(self, e):
        self.PopupMenu(MyPopupMenu(self), e.GetPosition())


def main():
    app = wx.App()
    frame = Example(None, title='右键菜单演示')
    frame.Show()
    app.MainLoop()

if __name__ == '__main__':
    main()
